<<<<<<< HEAD
// interface User {
//     name:string
//     age:number
//     sayHello():void
//   } 
=======
interface User {
    name:string
    age:number
    sayHello():void
} 
>>>>>>> origin/master

//利用ts书写一个函数，筛选出，数组中的指定类型数字求和

// 利用别名书写
// type Condition = (n : number) => boolean;

//接口的写法
<<<<<<< HEAD
// interface Condition {
//     ( n:number ): boolean
// }
=======
interface Condition {
    ( n:number ): boolean
}
>>>>>>> origin/master

// 同理类型别名也可以这样写
// type Condition = {
//     // 当大括号里无其他属性时，只有函数是
//     (n : number) => boolean;
// }


<<<<<<< HEAD
// type User = {
//     readonly id: string
//     name: string
//     age: number,
//     readonly arr: readonly string[]   限制User中的arr数组只读，且不能改变
// }

// let u: User = {
//     id: "123",
//     name: "Asdf",
//     age: 33,
//     arr:["Sdf", "dfgdfg"]
// }

// const arr: readonly number[] = [3, 4, 6];

// const arr: ReadonlyArray<number> = [3, 4, 6];

// interface Duck {
//     sound: "嘎嘎嘎"
//     swin(): void
// }

// let person = {
//     name: "伪装成鸭子的人",
//     age: 11,
//     sound: "嘎嘎嘎" as "嘎嘎嘎",
//     swin() {
//         console.log(this.name + "正在游泳，并发出了" + this.sound + "的声音");
//     }
// }

// let duck: Duck = {
//     sound: "嘎嘎嘎" as "嘎嘎嘎",
//     swin() {
//         console.log(this.name + "正在游泳，并发出了" + this.sound + "的声音");
//     }
// };

// interface User {
//     name?: string
//     age: number
// }

// interface Condition {
//     (n: number, i: number): boolean
// }

// function sum(numbers: number[], callBack: Condition) {
//     let s = 0;
//     for (let i = 0; i < numbers.length; i++) {
//         const n = numbers[i];
//         if (callBack(n, i)) {
//             s += n;
//         }
//     }
//     return s;
// }

// const result = sum([3, 4, 5, 7, 11], n => n % 2 !== 0);
// console.log(result);

//(value: number, index: number, array: number[]) => void

// [34, 4].forEach(it => console.log(it));




// function sum(numbers:number[],callBack:Condition) {
//     let temp = 0;
//     numbers.forEach(i=>{
//         if(callBack(i)){
//             temp += i
//         }

//     })
//     return temp;
// }

// const result = sum([1,4,3,5,22,3,4,7,2],(n)=>n % 2 !== 0);
// console.log(result);
=======



function sum(numbers:number[],callBack:Condition) {
    let temp = 0;
    numbers.forEach(i=>{
        if(callBack(i)){
            temp += i
        }

    })
    return temp;
}

const result = sum([1,4,3,5,22,3,4,7,2],(n)=>n % 2 !== 0);
console.log(result);
>>>>>>> origin/master

